import { ref } from "vue"
import { getId } from "../utils/todoLocalStorage.js"

export function useNewTodo(todoData) {
    const newTodoRef = ref("")
    const addTodo = () => {
        const value = newTodoRef.value && newTodoRef.value.trim()
        if(!value) {
            return
        }
        const todoObj =  {
            completed: false,
            title: value,
            id: getId()
        }
        // console.log(getId());
        todoData.value.push(todoObj)
        newTodoRef.value = ""
    }
    return {
        newTodoRef,
        addTodo
    }
}